package com.yc.exam.controller;

import com.yc.exam.entity.User;
import com.yc.exam.service.IUserService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.security.Principal;
import java.util.HashMap;

/**
 * 负责页面路由
 *
 * @author 75073
 */
@Controller
@RequestMapping("/index")
@AllArgsConstructor
public class IndexController {

  private final IUserService userService;

  @ApiOperation("跳转 登录页")
  @GetMapping("/login")
  public String login() {
    return "login";
  }

  @ApiOperation("跳转 注册页")
  @GetMapping("/register")
  public String register() {
    return "register";
  }

  @ApiOperation("跳转 首页")
  @GetMapping({"/home", "/"})
  public String home(Model model, Principal principal) {
    HashMap<Object, Object> entity = new HashMap<>();
    entity.put("username", principal.getName());
    model.addAttribute("entity", entity);
    return "home";
  }

  @ApiOperation(value = "加载主页")
  @GetMapping("/main")
  public String main() {
    return "main";
  }

  @ApiOperation(value = "加载用户管理页面")
  @GetMapping("/user")
  public String user() {
    return "users/user";
  }

  @ApiOperation(value = "跳转 404 页面")
  @GetMapping("/404")
  public String error404() {
    return "error/404";
  }

  @ApiOperation(value = "跳转 403 页面")
  @GetMapping("/403")
  public String error403() {
    return "error/403";
  }

  @ApiOperation(value = "跳转 500 页面")
  @GetMapping("/500")
  public String error500() {
    return "error/500";
  }

  @ApiOperation(value = "跳转 菜单页")
  @GetMapping("/menu")
  public String menu() {
    return "menu/menu";
  }

  @ApiOperation(value = "跳转 角色页")
  @GetMapping("/role")
  public String role() {
    return "role/role";
  }

  @ApiOperation(value = "跳转到修改密码的页面")
  @GetMapping("/user/editPassword")
  public String changePassword() {
    return "users/edit_password";
  }

  @ApiOperation(value = "跳转到修改用户")
  @GetMapping("/user/updateSelfInfo")
  public String modifyUser(Model model, Principal principal) {
    User entity = userService.loadUserByUserName(principal.getName());
    model.addAttribute("entity", entity);
    return "users/user_edit";
  }

  @ApiOperation(value = "跳转到作业管理页面")
  @GetMapping("exam")
  public String job() {
    return "exam/exam";
  }

  @ApiOperation(value = "跳转到题目管理页面")
  @GetMapping("topic")
  public String tpoic() {
    return "topic/topic";
  }

  @ApiOperation(value = "跳转到课程管理页面")
  @GetMapping("course")
  public String course() {
    return "course/course";
  }

  @ApiOperation(value = "跳转到提问页面")
  @GetMapping("answer")
  public String answer() {
    return "answer/answer";
  }

  @ApiOperation(value = "跳转到问题列表页")
  @GetMapping("answer/list")
  public String answerList() {
    return "answer/list";
  }

  @ApiOperation("跳转到课程订阅页面")
  @GetMapping("course/subscribe")
  public String courseSubscription() {
    return "course/subscribe";
  }

  @ApiOperation("跳转到我的试卷生成及阅卷系统页面")
  @GetMapping("exam/list")
  public String toExamList() {
    return "exam/list";
  }

  @GetMapping("exam/answerQuestions")
  public String toAnswerQuestions() {
    return "exam/answerQuestions";
  }

  /** 跳转到预览页面 */
  @GetMapping("exam/preview")
  public String toPreview() {
    return "exam/preview";
  }
  @GetMapping("/grade")
  public String toGrade(){
    return "grade/grade";
  }

  @ApiOperation("跳转到我的试卷生成及阅卷系统页面")
  @GetMapping("exam/list2")
  public String toExamList2() {
    return "exam/list2";
  }

  @ApiOperation("跳转到老师查看学生成绩页面")
  @GetMapping("grade/teacher")
  public String gradeTeacher() {
    return "grade/grade2";
  }

  @ApiOperation("跳转到发送试卷页面")
  @GetMapping("exam/send")
  public String sendExam() {
    return "exam/send";
  }

}
